package com.gdust.gkyx.search.controller;

import com.gdust.gkyx.common.result.Result;
import com.gdust.gkyx.model.search.SkuEs;
import com.gdust.gkyx.search.service.SkuService;
import com.gdust.gkyx.vo.search.SkuEsQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName: SkuApiController
 * Package: com.gdust.gkyx.search.controller
 * Description:
 *
 * @Author syun
 * @Create 2025/1/26 11:11
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/search/sku")
public class SkuApiController {

    @Autowired
    private SkuService skuService;



    /**
     * //上架
     * @param skuId
     * @return
     */
    @GetMapping("inner/upperSku/{skuId}")
    public Result upperSku(@PathVariable Long skuId) {
        skuService.upperSku(skuId);
        return Result.ok(null);
    }

    /**
     * //下架
     * @param skuId
     * @return
     */
    @GetMapping("inner/lowerSku/{skuId}")
    public Result lowerSku(@PathVariable Long skuId) {
        skuService.lowerSku(skuId);
        return Result.ok(null);
    }

        /**
     * //查询分类商品
     * @param page 当前页
     * @param limit 每页记录数
     * @param skuEsQueryVo 分页条件
     * @return
     */
        //查询分类商品
        @GetMapping("{page}/{limit}")
        public Result listSku(@PathVariable Integer page,
                              @PathVariable Integer limit,
                              SkuEsQueryVo skuEsQueryVo) {
            //创建pageable对象，0代表第一页
            Pageable pageable = PageRequest.of(page-1,limit);
            Page<SkuEs> pageModel = skuService.search(pageable,skuEsQueryVo);
            return Result.ok(pageModel);
        }


    //获取爆款商品
    @GetMapping("inner/findHotSkuList")
    public List<SkuEs> findHotSkuList() {
        return skuService.findHotSkuList();
    }

//    //更新商品热度
    @GetMapping("inner/incrHotScore/{skuId}")
    public Boolean incrHotScore(@PathVariable("skuId") Long skuId) {
        skuService.incrHotScore(skuId);
        return true;
    }

}

